package com.NeuglsWorkStudio.UI.Buttons
{
	import com.NeuglsWorkStudio.Colors.HSL;
	
	import flash.display.DisplayObject;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextFormat;

	public class TEffectedButtonEx extends TEffectedButton
	{
		private var _FNormal:Sprite;
		private var _FOver:Sprite;
		public static var ButtonWidth:Number=80;
		public static var ButtonHeight:Number=30;
		
		public function TEffectedButtonEx(ACaption:String="", IsHtml:Boolean=true, BaceColor:int=0x222222)
		{
			super(ACaption, IsHtml, BaceColor);
			Init();			
			
			FMouseOut(null);
		}
		
		private function Init():void{
			var w:Number=this.Width>ButtonWidth?this.Width:ButtonWidth;
			var borderColor:int=HSL.AddLightToColor(BaceColor,0.2);
			
			FCaptionField.x=(w-FCaptionField.textWidth)/2;
			FCaptionField.y=(ButtonHeight-FCaptionField.height)/2;
			
			var a:TextFormat=this.CaptionFormat;
			a.color=0xFFFFFF;
			this.CaptionFormat=a;
			
			_FNormal=BuildBitmapData(w,ButtonHeight,5,1,borderColor,HSL.AddLightToColor(BaceColor,0.16),HSL.AddLightToColor(BaceColor,0.12));
			_FOver=BuildBitmapData(w,ButtonHeight,5,1,borderColor,HSL.AddLightToColor(BaceColor,0.18),HSL.AddLightToColor(BaceColor,0.15));
		}
		
		override protected function FMouseOut(Event:MouseEvent):void{
			this.contains(_FNormal)?this.removeChild(_FNormal):_FOver;
			!this.contains(_FOver)?this.addChildAt(_FOver,0):_FOver;
		}
		
		override protected function FMouseOver(Event:MouseEvent):void{
			this.contains(_FOver)?this.removeChild(_FOver):_FOver;
			!this.contains(_FNormal)?this.addChildAt(_FNormal,0):_FOver;
		}
		
		
		protected function BuildBitmapData(Width:Number,Height:Number,RoundRadius:Number,
			BorderSize:Number,BorderColor:int,TopPartColor:int,BottomColor:int):Sprite{
			
			var result:Sprite=new Sprite();
			with(result.graphics){
				/**lineStyle(BorderSize,0x7A7A7A);
				beginFill(0,0);
				drawRoundRect(0,0,Width-2*BorderSize,
					Height-2*BorderSize,
					2*RoundRadius,
					2*RoundRadius
				);**/
				/**lineStyle(BorderSize,BorderColor);
				drawRoundRect(BorderSize,BorderSize,Width-4*BorderSize,
					Height-4*BorderSize,
					2*RoundRadius,
					2*RoundRadius
				);**/
				
				lineStyle(null,0,0);
				beginFill(TopPartColor,1);
				drawRoundRectComplex(2*BorderSize,2*BorderSize,Width-4*BorderSize,
					(Height-4*BorderSize)/2,RoundRadius,RoundRadius,0,0);
				beginFill(BottomColor,1);
				drawRoundRectComplex(2*BorderSize,(Height-4*BorderSize)/2,Width-4*BorderSize,
					(Height-4*BorderSize)/2,0,0,RoundRadius,RoundRadius);
				endFill();
			}
			
			return result;
			
		}
	}
}